package main

import (
	_ "MaternalBaby/api/routers"
	"MaternalBaby/api/utils"
	"encoding/json"
	"net/http"

	"github.com/astaxie/beego"
)

func main() {
	go aliyunStsRun()
	beego.Run()
}

func aliyunStsRun() {
	stsClient := utils.NewClient(utils.AccessKeyID, utils.AccessKeySecret, utils.RoleArn, utils.SessionName)

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		resp, err := stsClient.AssumeRole(3600)
		if err != nil {
			beego.Error(err)
		}
		stsResult, err := json.Marshal(resp.Credentials)
		if err != nil {
			beego.Error(err)
		} else {
			_, err := w.Write(stsResult)
			if err != nil {
				beego.Error(err)
			}
		}
	})
	http.ListenAndServe(":8067", nil)

}
